package com.pms.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;


import com.pms.util.RowMapper;
import com.pms.entity.User;
import com.pms.util.DBHelp;

public class UserDao {
	private DBHelp<User> db = new DBHelp<User>();
	
	public User findByName(String name) {
		String sql = "select id,username,password from t_user where username =?";
		return db.executeQueryForObject(sql, new UserRowMapper(),name);
	}
	
	public List<User> findAllname(){
		String  sql="select id,username,password from t_user";
		return db.executeQueryForList(sql, new UserRowMapper());
	}
	public User findById(String id){
		String sql = "select id,username,password from t_user where id =?";
		return db.executeQueryForObject(sql, new UserRowMapper(),id);
	}
	private class UserRowMapper implements RowMapper<User> {

		public User mapperRow(ResultSet rs) throws SQLException {
			User user = new User();
			user.setId(rs.getString("id"));
			user.setUsername(rs.getString("username"));
			user.setPassword(rs.getString("password"));
			
			return user;
		}
		
	}



}
